package com.lamatek.tags.google;

import java.io.Serializable;
import java.util.Vector;

import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * GoogleMapCircleTag
 * 
 * This class represents a &lt;googlemaps:circle> tag. Developers should not
 * override this class.
 * 
 * @author Tom Cole
 * @version 0.40
 */
public class GoogleMapCircleTag extends TagSupport implements Serializable, GoogleMapEventListener {
    
    String id = null;
    String point = null;
    double radius = 1.00d;
    String color = "#ff0000";
    int weight = 2;
    float opacity = 0.50f;
    Vector events = null;
    /**
     * Overrides doStartTag() in TagSupport. Developers should not override this method. 
     * If they do, they must call super.doStartTag() to ensure the tag get added to the
     * tree properly.
     */
    public int doStartTag() {
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapTag) {
                ((GoogleMapTag) tag.getParent()).addCircle(this);
                return SKIP_BODY;
            }
            tag = tag.getParent();
        }
        return SKIP_BODY;
    }
    /**
     * Sets the color used to draw this overlay. Default is #ff0000.
     * 
     * @param color The color code in hexadecimal format.
     */
    public void setColor(String color) {
        this.color = color;
    }
    /**
     * Sets the 0-1 based opacity of the circle. 0 is invisible, 1 is fully opaque.
     * 
     * @param opacity A float from 0-1.
     */
    public void setOpacity(float opacity) {
        this.opacity = opacity;
    }
    /**
     * Sets the radius of the circle (in miles) from the centerpoint.
     * 
     * @param radius A double indicating miles.
     */
    public void setRadius(double radius) {
        this.radius = radius;
    }
    /**
     * Returns the current radius set for this circle.
     * 
     * @returns A double indicating miles of radius.
     */
    public double getRadius() {
        return radius;
    }
    /**
     * Sets the weight (width) of the circle line in pixels.
     * 
     * @param weight An int specifying line width in pixels.
     */
    public void setWeight(int weight) {
        this.weight = weight;
    }
    /**
     * Returns the point id that is used as the centerpoint.
     * 
     * @return A String representing the centerpoint's id.
     */
    public String getPoint() {
        return point;
    }
    /**
     * Sets the id of the point to be used as the centerpoint for the circle.
     * 
     * @param point A String representing the id of the centerpoint.
     */
    public void setPoint(String point) {
        this.point = point;
    }
    /**
     * Returns the color used to draw this circle, in hexadecimal format.
     * 
     * @return A hexadecimal String representing a color.
     */
    public String getColor() {
        return color;
    }
    /**
     * Returns the current opacity level (0-1) of the circle line.
     * 
     * @return A float indicating opacity level.
     */
    public float getOpacity() {
        return opacity;
    }
    /**
     * Returns the current width (in pixels) if the circle line.
     * 
     * @return An int representing line width (in pixels).
     */
    public int getWeight() {
        return weight;
    }
    /**
     * Returns the id of this circle.
     * 
     * @return The circle's id.
     */
    public String getId() {
        return id;
    }
    /**
     * Sets the id for this circle.
     * 
     * @param id The circle's unique id.
     */
    public void setId(String id) {
        this.id = id;
    }
    /**
     * Adds an event listener to this overlay.
     * 
     * @param event A GoogleMapEventTag
     */
    public void addEvent(GoogleMapEventTag event) {
        if (events == null)
            events = new Vector();
        events.add(event);
    }
    /**
     * Returns the list of currently registered event listeners
     * for this overlay.
     * 
     * @return A Vector of GoogleMapEventTags
     */
    public Vector getEvents() {
        return events;
    }
}
